package com.wuzuqing.android.eightdiagrams.task;

import com.wuzuqing.android.eightdiagrams.model.QiMenDunJiaItem;
import com.wuzuqing.android.eightdiagrams.model.QiMenDunJiaModel;

import java.util.ArrayList;
import java.util.List;

/**
 * @CopyRight: 广州仰望星空云科技有限公司
 * @Author : wuzuqing
 * @Email:wuzuqing@xinyu668.com
 * @CreateTime: 26.7.24 3:30 PM
 * @Description: 请写描述
 */
public class QiMenDunJiaStep6Task extends IQiMenDunJiaTask {
    QiMenDunJiaModel model;

    public QiMenDunJiaStep6Task(QiMenDunJiaModel model) {
        this.model = model;
    }

    @Override
    public void handleTask() {
        List<QiMenDunJiaItem> list = model.getList();
        List<String> xingArr = new ArrayList<>(QiMenDunJiaModel.xingArr);
        int zhiGongNum = model.getZhiGongNum();
        String zhiXin = model.getZhiXin();
        if ("天禽".equals(zhiXin)) {
            zhiXin = "天芮";
        }
        if (zhiGongNum == 5) {
            zhiGongNum = 2;
        }
        int index = listArr.indexOf(zhiGongNum);
        int xingIndex = xingArr.indexOf(zhiXin); // 7
        for (int k = 0; k < xingArr.size(); k++) {
            int realIndex = (index + k) % xingArr.size();
            int realGongNum = listArr.get(realIndex);
            int xingRealIndex = (xingIndex + k) % 8;
            QiMenDunJiaItem temp = getDunJia(list, realGongNum);
            if (temp != null) {
                //定九星
                try {
                    temp.setJiXing(xingArr.get(xingRealIndex));
                }catch (Exception e){
                    e.printStackTrace();
                }
            }
        }
    }
}
